package net.esj.background.struts2.view;

import net.esj.background.Constants;
import net.esj.background.support.multi.Portal;
import net.esj.basic.view.BaseAction;

import org.apache.struts2.ServletActionContext;

/**
 * @author Administrator
 *
 */
public class DyncSkipAction extends BaseAction implements Constants{

	/**
	 * 
	 */
	private static final long serialVersionUID = 3534220814059323323L;
	
	private String namespace;
	private String actionName;

	@Override
	public String execute() throws Exception {
		String uri = ServletActionContext.getRequest().getRequestURI();
		boolean has = false;
		for(Portal portal : Portal.getAll()){
			String ns = uri.substring(ACTION_NAMESPACE_PREFIX.length());
			if(ns.startsWith(portal.getNamespace())){
				getSession().setAttribute(PORTAL_SESSION_KEY, portal);
				has = true;
				break;
			}
		}
		
		if(has){
			uri = uri.substring(uri.lastIndexOf("/")+1,uri.lastIndexOf(".")); 
			namespace = "/dynamically/backstage-manager";
			actionName = uri;
		}else{
			namespace = "";
			actionName = "error";
		}
		return SUCCESS;
	}
	
	public String getNamespace() {
		return namespace;
	}
	public void setNamespace(String namespace) {
		this.namespace = namespace;
	}
	public String getActionName() {
		return actionName;
	}
	public void setActionName(String actionName) {
		this.actionName = actionName;
	}
	
	
}
